var a,
  t = require("../../res/www.a9a.cn.js"),
  o = getApp();
Page({
  data: { tguid: 0, admid: 0 },
  onLoad: function (e) {
    wx.showLoading({ title: "玩命加载中...", mask: !0 });
    var i,
      n,
      s = this;
    if (t.ifint(e.tguid)) (i = e.tguid), (n = t.ifint(e.admid) ? e.admid : 0);
    else {
      for (
        var c = decodeURIComponent(e.scene), r = {}, g = 0;
        g < c.split("*").length;
        g++
      ) {
        var d = c.split("*")[g].split("/");
        r[d[0]] = d[1];
      }
      (i = t.ifint(r.t) ? r.t : 0), (n = t.ifint(r.a) ? r.a : 0);
    }
    o.get_config("_ZEAI").then(function (e) {
      s.setData({
        color: e.color,
        rgbcolor: t.c16_rgb(e.color),
        tguid: i,
        admid: n,
      }),
        wx.setNavigationBarColor({
          backgroundColor: e.color,
          frontColor: "#ffffff",
        }),
        wx.setBackgroundColor({
          backgroundColor: e.color,
          backgroundColorTop: e.color,
          backgroundColorBottom: e.color,
        }),
        (a = wx.getStorageSync("COOK_U")),
        o.ajax({
          url: "tg.php",
          data: {
            submitok: "TGHB",
            openid: a.openid,
            tguid: s.data.tguid,
            admid: s.data.admid,
          },
          success: function (a) {
            1 == a.flag
              ? (s.setData({
                  bg_url: a.bg_url,
                  photo_m_url: a.photo_m_url,
                  ewmurl: a.ewmurl,
                }),
                wx.getImageInfo({
                  src: a.bg_url,
                  success: function (t) {
                    s.setData({
                      bg_path: t.path,
                      bg_width: t.width,
                      bg_height: t.height,
                    }),
                      wx.getImageInfo({
                        src: a.ewmurl,
                        success: function (t) {
                          s.setData({ ewm_path: t.path }),
                            wx.getImageInfo({
                              src: a.photo_m_url,
                              success: function (a) {
                                s.setData({ photo_m_path: a.path }), s.makeFn();
                              },
                            });
                        },
                      });
                  },
                }))
              : wx.showModal({
                  content: a.msg,
                  confirmColor: s.data.color,
                  confirmText: "朕知道了",
                  showCancel: !1,
                  success: function (a) {
                    wx.navigateBack();
                  },
                }),
              wx.hideLoading();
          },
        });
    });
  },
  makeFn: function () {
    this.createNewImg(this.data.bg_url);
  },
  createNewImg: function () {
    wx.showLoading({ title: "生成海报", mask: !0 });
    var a = this,
      t = wx.createCanvasContext("mycanvas", a);
    t.restore(),
      t.drawImage(a.data.bg_path, 0, 0, a.data.bg_width, a.data.bg_height);
    var o = 136,
      e = 136,
      i = (a.data.bg_width - 136) / 2,
      n = 318;
    t.save(),
      t.beginPath(),
      t.arc(o / 2 + i, e / 2 + n, o / 2, 0, 2 * Math.PI, !1),
      t.clip(),
      t.drawImage(a.data.photo_m_path, i, n, o, e),
      t.restore(),
      (o = 210),
      (e = 210),
      (i = (a.data.bg_width - 210) / 2),
      (n = 810),
      t.save(),
      t.beginPath(),
      t.arc(o / 2 + i, e / 2 + n, o, 0, 360, !1),
      t.clip(),
      t.drawImage(a.data.ewm_path, i, n, o, e),
      setTimeout(function () {
        t.draw(!1, function () {
          wx.canvasToTempFilePath(
            {
              canvasId: "mycanvas",
              fileType: "png",
              success: function (t) {
                wx.hideLoading();
                var o = t.tempFilePath;
                a.setData({ imagePath: o });
              },
              fail: function (a) {},
            },
            a
          );
        });
      }, 300);
  },
  saveFn: function () {
    wx.saveImageToPhotosAlbum({
      filePath: this.data.imagePath,
      success: function (a) {
        wx.showToast({ title: "保存成功", icon: "success", mask: !0 });
      },
    });
  },
  closeFn: function () {
    this.setData({ imagePath: "" }), wx.navigateBack();
  },
  sharepicFn: function () {
    wx.showShareImageMenu({ path: this.data.imagePath });
  },
});
